using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Management;

namespace LeastPrivilege.CustomBasicAuthentication
{
    internal class AuthenticationFailureEvent : WebAuthenticationFailureAuditEvent
    {
        public AuthenticationFailureEvent(object sender, string username)
            : base("Authentication failure", sender, EventCodes.AuthenticationFailure, username)
        {}
    }

    internal class AuthenticationSuccessEvent : WebAuthenticationSuccessAuditEvent
    {
        public AuthenticationSuccessEvent(object sender, string username)
            : base("Authentication success", sender, EventCodes.AuthenticationSuccess, username)
        { }
    }

    internal class CredentialCacheHitEvent : WebAuditEvent
    {
        public CredentialCacheHitEvent(object sender, string username)
            : base("Cache hit for: " + username, sender, EventCodes.CacheHit)
        { }
    }

    internal class CredentialCacheMissEvent : WebAuditEvent
    {
        public CredentialCacheMissEvent(object sender, string username)
            : base("Cache miss for: " + username, sender, EventCodes.CacheHit)
        { }
    }

    internal class CredentialCacheAddEvent : WebAuditEvent
    {
        public CredentialCacheAddEvent(object sender, string username)
            : base("Credential identifier added for: " + username, sender, EventCodes.CacheAdd)
        { }
    }

    internal class CredentialCacheAddErrorEvent : WebFailureAuditEvent
    {
        private Exception _exception;

        public CredentialCacheAddErrorEvent(object sender, string username, Exception exception)
            : base("Failed to add credential identifier for: " + username, sender, EventCodes.CacheAdd)
        {
            _exception = exception;
        }

        public override void FormatCustomEventDetails(WebEventFormatter formatter)
        {
            base.FormatCustomEventDetails(formatter);

            formatter.AppendLine(_exception.ToString());
        }
    }
}
